package com.eric.media.camera.barCode.test;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.ImageView;

import com.eric.media.R;
import com.eric.media.camera.barCode.EncodingUtils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_bar_code_create)
public class QRBarCodeCreateActivity extends AppCompatActivity {
    @ViewById(R.id.img_Qr)
    ImageView img_Qr;
    @ViewById(R.id.img_barCode)
    ImageView img_barCode;
    String myBlogUrl = "http://blog.csdn.net/lu1024188315";
    @AfterViews
    void initViews(){
        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        //要生成的二维码的宽度  一般二位为 正方法 那么高度就等宽度
        int width = (int) (metrics.widthPixels * 0.5);
        if (width <= 0){
            width = 300;
        }
        Bitmap logoBp = BitmapFactory.decodeResource(getResources(),R.mipmap.icon_voice_main);
        Bitmap resultBp =  EncodingUtils.createQRCode(myBlogUrl,width,width,logoBp);
        if (null != resultBp){
            img_Qr.setImageBitmap(resultBp);
        }

        Bitmap barCodeBp = EncodingUtils.createBarcode("20115101106",300,150,true);
        if (null != barCodeBp){
            img_barCode.setImageBitmap(barCodeBp);
        }

    }


}
